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: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'.
Ads
Related Tutorials/Questions & Answers:
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
Advertisements
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&
sql-jdbc
sql-jdbc how to execute select query using prepared statement
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
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 spatio-temporal query
JDBC-
SQL spatio-temporal query Any one give me a
JDBC sql query for my spatio temporal query?
Trajectory table
OBJID PLACE
7 H
8
Q
9 W
10... as shown in above. I want a spatio-temporal query using
JDBC-
SQL to retrieve
JDBC- SQL spatio-temporal query
JDBC-
SQL spatio-temporal query Any one give me a
JDBC sql query for my spatio temporal query?
Trajectory table
OBJID PLACE
7 H
8
Q
9 W
10... as shown in above. I want a spatio-temporal query using
JDBC-
SQL to retrieve
SQL STATEMENT in JDBC in NETBEANS IDE
SQL STATEMENT in
JDBC in NETBEANS IDE Iam using NETBEANS IDE. Iam developing a bank application. Using
JDBC in SERVLETS
For the withdraw function, "bal" and "ano" are user inputs when i wrote like,
st.executeQuery("UPDATE
JDBC Batch Example With SQL Insert Statement
JDBC Batch Example With
SQL Insert Statement:
In this tutorial, we are discuss about insert
SQL statement with the
jdbc
batch.
First of all, we...;com.mysql.jdbc.Driver");
connection = DriverManager.getConnection
("
jdbc
JDBC Batch Example With SQL Update Statement
JDBC Batch Example With
SQL Update Statement:
In this tutorial, we are discuss about update
SQL statement with the
jdbc
batch.
Now we will create a java...;com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"
jdbc:mysql
JDBC Batch Example With SQL Select Statement
JDBC Batch Example With
SQL Select Statement:
In this example, we are discuss about
SQL select statement with
JDBC batch
process. We will create
SQL...;
static final String url = "
jdbc
exception
exception wHEN RUNTIME
EXCEPTION CLASS IS SUB OF
EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED
EXCEPTION
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