Solved

DB Connection problem in java

Posted on 2009-07-07
4
156 Views
Last Modified: 2013-11-23
Hi ,

i am using below code when i run java envi its says ORA-00911: invalid character
that same query is runing and insert the values in back end !!
can u tell me the problem
String url = "jdbc:oracle:thin:@localhost:1521";

		  try {

				try {

				 Class.forName("oracle.jdbc.driver.OracleDriver");

					// System.out.println("Failed to load isqlPlus driver.");

					//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

				}
 

				catch (Exception ae) {

					ae.printStackTrace();

				}
 

				try {
 

					String url1 = System.getProperty("JDBC_URL");

					if (url1 != null)

						url = url1;

					Connection con = DriverManager.getConnection(url,

							"system", "tspl");

					PreparedStatement psmnt=null;

					String query="insert into gen_info(EMP_NAME,EMP_ID,TECH) "+ "values(?,?,?);";

					//Statement st=con.createStatement();

					

					psmnt = con.prepareStatement(query);

					psmnt.setString(1,"Sathish");

					psmnt.setString(2,"E11007");

					psmnt.setString(3,"Java");

					

				boolean s = psmnt.execute();

					if (s)

					{

						System.out.println("Succesfully inserted");

					}

					else 

					{

						System.out.println("Cant Insert");

					}

						//st.execute(query);

					con.close();

				} catch (Exception e) {

					e.printStackTrace();

				}

			} catch (Exception e) {

				e.printStackTrace();

			}

Open in new window

0
Comment
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
try getting rid of the ;
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
Comment Utility
what i didnt get u ??
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
the ; at the end of your sql
0
 
LVL 15

Expert Comment

by:fsze88
Comment Utility
in line 21 , will it cause by missed space in sql statement?
String query="insert into gen_info (EMP_NAME, EMP_ID, TECH) "+ " values(?,?,?) ";
also, you can try System.out.println(query) to see is there any invalid characters ?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now