Home Answers Viewqa JDBC jdbc sql exception.

 
 


ravibabu
jdbc sql exception.
2 Answer(s)      a year and 9 months ago
Posted in : JDBC

import java.sql.*;

import java.io.*; class InsertEx { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:ora","system","tiger"); Statement stmt=con.createStatement(); DataInputStream din=new DataInputStream(System.in); while(true) { System.out.println("Enter Employee number"); String s=din.readLine(); int no=Integer.parseInt(s); System.out.println("Enter Employee name"); String name=din.readLine(); System.out.println("Enter Employee salary"); s=din.readLine(); Float sal=Float.parseFloat(s); System.out.println("Enter Employee address"); String addr=din.readLine(); int count=stmt.executeUpdate("insert into myemp values("+no+",'"+name+",'"+sal+",'"+addr+"')"); if(count>0) System.out.println("Insert record successfully"); else System.out.println("record not Insert"); System.out.println("enter another record[yes/no]:"); String choice=din.readLine(); if(!choice.equalsIgnoreCase("yes")); break; } } } Error is:

E:>javac InsertEx.java Note: InsertEx.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

E:>java InsertEx Enter Employee number 1 Enter Employee name ravi Enter Employee salary 9000 Enter Employee address hyd Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC driver for Or acle][Oracle]ORA-00917: missing comma at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source) at InsertEx.main(InsertEx.java:23)

View Answers

August 27, 2011 at 1:03 PM


import java.io.*; 
import java.sql.*;
class InsertEx{
    public static void main(String args[])throws Exception { 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:student","","");
        Statement stmt=con.createStatement(); 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        boolean status=false;
        do{
            System.out.println("Enter Employee number");
            int no=Integer.parseInt(br.readLine()); 
            System.out.println("Enter Employee name");
            String name=br.readLine(); 
            System.out.println("Enter Employee address");
            String addr=br.readLine();
            System.out.println("Enter Employee salary");
            int sal=Integer.parseInt(br.readLine()); 

            int count=stmt.executeUpdate("insert into employee(empid,name,address,salary)  values("+no+",'"+name+"','"+addr+"',"+sal+")");
            if(count>0)
            System.out.println("Insert record successfully");
            else
            System.out.println("record not Insert"); 
            System.out.println("enter another record[yes/no]:");
            String choice=br.readLine();
            if(!choice.equalsIgnoreCase("yes")){
            status=true;
            }
            }
            while(!status);
            }
            }

August 27, 2011 at 2:47 PM


For the above code, do the following:

Follow these steps:

1)Go to the start>>Control Panel>>Administrative Tools>> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

We have a dsn named 'student'.









Related Pages:
jdbc sql exception.
jdbc sql exception.  import java.sql.*; import java.io.*; class InsertEx { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc
jdbc odbc sql server exception
jdbc odbc sql server exception  Hi, I am trying to use sql server with java jdbc odbc but I am getting this exception java.sql.SQLException: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '@P1
SQL Exception
SQL Exception  I want stores data in to the databse table but it can't be stores it shows an error about sql exception. blackberry.html <...("jdbc:odbc:asset"); String Qry = "INSERT INTO blackberry&
Enhanced SQL Exception Handling
Enhanced SQL Exception Handling       5. Enhanced SQL Exception Handling: A lot of improvement has been done regarding Exception handling in the following fields: Iterable SQL Exception
JDBC Exception
JDBC Exception      ... the execution of program. Exception Occurred in JDBC Connectivity when a connection... with ExampleThe Tutorial illustrates an example from JDBC Exception
jdbc & sql related project - JDBC
jdbc & sql related project  code using jdbc,odbc,swing,MySql classes to create front-end of any jdbc that allows the user to select any database from a list and execute any sql query related to the selected database e.g
SQL QUERY - JDBC
SQL QUERY  I m running a query using apache tomcat the sql query is on adding an employee in the database whenever i click on add after inserting the values i am getting a java.lang.nullpointer exception
creating jdbc sql statements - JDBC
creating jdbc sql statements  I had written the following program...=DriverManager.getConnection("jdbc:odbc:second"); stmt=con.createStatement..."+rs.getString(2)+"\t"+rs.getFloat(3)); } catch(Exception e
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect...; String url = "jdbc:mysql://localhost:3306/"; String dbName
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC  write a JDBC program to display the result of any query...").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" ); String sql = "Select * from data"; Statement stmt
JDBC
retrieve the value from database into dropdown list using JDBC SQL 2005  How to retrieve the value from database into dropdown list using JDBC & SQL 2005?   JSP Code: Create table country(country_id,country
sql - SQL
("SQL statement is not executed!"); } } catch (Exception e...sql functions with examples  I need sql functions with examples... = "jdbc:mysql://localhost:3306/"; String db = "register"
sql - SQL
connectionURL = "jdbc:mysql://192.168.10.211:3306/amar"; java.sql.Connection... is not inserted"); } } catch (Exception e) { System.out.println(e
exception
exception  Identify the reason for SQLException exception, which..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost..."); ps.executeUpdate(); } catch(Exception e
jdbc adapter exception - JDBC
jdbc adapter exception  Through JDBC, I connected to MySQL Server... = FOREIGN_KEY_CHECKS = 0" to JDBC URL( i.e., "jdbc:mysql://MyHost/myDB").Modified URL is: "jdbc:mysql://MyHost/myDB?sessionVariables = FOREIGN_KEY_CHECKS = 0
Java sql Exception
Java sql Exception  difference between sql exception class and sql warning class
JDBC - JDBC
JDBC  how to do connectivity with SQL Server and MS Access in java... String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D... Exception { Connection con = null; try
JDBC - JDBC
); Statement stmt=con.createStatement(sql); here Connection and Statement both... implementing class.  Hi friend, Example of JDBC Connection with Statement... database table!"); Connection con = null; String url = "jdbc:mysql
JDBC - JDBC
JDBC connection to database and show results  Check if the database connectivity is working fine and show results. Also through an exception... Exception{ Connection conn=null; try{ Class.forName
jdbc - JDBC
in JSP to create a table. 2)how desc can be written in JDBC concepts  ... = null; String url = "jdbc:mysql://localhost:3306/"; String db...){ System.out.println("SQL statement is not executed!"); } } catch
JDBC - JDBC
"); con = DriverManager.getConnection("jdbc:mysql://192.168.10.211... s){ System.out.println("SQL statement is not executed!"); } } catch (Exception e){ e.printStackTrace
sql - JDBC
key constraints in SQL server  Does SQL have a FOREIGN KEY constraints in a Table
sql - JDBC
SQL joins queries   Hi, can anyone give me the couple of SQL joins queries with examples
JDBC - JDBC
JDBC  how can i do jdbc through oracle.. pls if u can send me d.... thanking u santosh.  Hi Friend, Use JDBC with Oracle Follow...) Load and Register the JDBC driver:*********** DriverManager.registerDriver(new
jdbc - JDBC
jdbc   kindly give the example program for connecting oracle dase...*; import oracle.jdbc.driver.*; import oracle.sql.*; 2) Load and Register the JDBC...,you have to use: Connection conn = DriverManager.getConnection("jdbc:oracle
sql-jdbc
sql-jdbc  how to execute select query using prepared statement
jdbc - JDBC
Example!"); Connection con = null; String url = "jdbc:mysql://localhost...){ System.out.println(s); } } catch (Exception e...; String url = "jdbc:mysql://192.168.10.211:3306/amar"; String driver
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
sql exception - JSP-Servlet
sql exception  Dear sir , I am working in a web-based project, In my system it is working fine but at client side getting the following exception so how to resolve this help me... java.sql.SQLException: ORA-28231
sql - JDBC
://www.roseindia.net/jdbc/jdbcconnectivity.shtml You will find the solution. Thanks
Sql - JDBC
SQL Statement and prepared statement  What is Statement and prepared statement in SQL  Statement and prepared statement are the interfaces declared in JAVA.SQL.While you connecting to a database these are required.If
insertion in SQL - SQL
in the database because of single code in the name. dbase is MS-SQL emp.name data type... as I know string parameter in SQL is denoted as 'john' . I think thats why...("jdbc:mysql://localhost:3306/userdetails","root","root"); try{ String
JDBC4.0-SQL Exception Handling Enhancements
categories of SQLException introduced in JDBC 4.0: SQL non-transient exception SQL... of the SQLException is corrected. The new exception classes that are added in JDBC 4.0...JDBC4.0-SQL Exception Handling Enhancements Exception handling is an important
exception at runtime - JDBC
exception at runtime  while i executing this source code:- import...; String url = "jdbc:mysql://localhost:3306/"; String dbName = "bank"; String... (Exception e) { e.printStackTrace(); } } } i got an exception
java runtime exception - JDBC
."); Connection con = null; String url = "jdbc:mysql://localhost:3306..."); } catch (Exception e) { e.printStackTrace(); } } } i got an exception that classnotfoundexception . how can i remove
sql query - SQL
sql query  hi sir,i have a month and year numbers,when i am enter a month and year in sql query then i want results for 1st day of month to last day..."); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost
SQL or UNICODE - SQL
SQL or UNICODE   Hi again............ I have got something new... ...... I had also change my backhand to SQL SERVER but retrieves same for UNICODE... = DriverManager.getConnection("jdbc:odbc:access"); Scanner input=new Scanner(System.in
SQL query - SQL
SQL query  hi sir/Madam i am using MS Access where i have table...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:access...+")"); } } catch(Exception e){ System.out.println(e); e.printStackTrace
Exception in thread "main" java.lang.ClassCastException
*; public class Test_jdbc { public Test_jdbc() { } // executes single SQL query...Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown...; public class Testjdbc { public Testjdbc() { } // executes single SQL query public
sql query - JDBC
sql query  I need a SQL query to add data into database
hi - SQL
hi  hi sir,i want to create a database in oracle,not in my sql sir...()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle...=st.executeUpdate("CREATE DATABASE test"); st.close(); conn.close(); } catch(Exception e
jdbc front end - JDBC
jdbc front end  a code written using JDBC,ODBC,SQL and swing only... that can execute the SQL queries related to that database.  Hi Friend..."); Connection connect =DriverManager.getConnection("jdbc:odbc:access","",""); Statement st

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.