?
Solved

DB Connection problem in java

Posted on 2009-07-07
4
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24792896
try getting rid of the ;
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 24792903
what i didnt get u ??
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 24792911
the ; at the end of your sql
0
 
LVL 15

Expert Comment

by:fsze88
ID: 24792944
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

764 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