Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello everyone.
I have a problem I have searched too much but I can't solve this. I am using netbeans and I have an oracle database. This is my first time to connect an application with a database. Simply, I have a form at netbeans and a table at database.

http://www.imagetoo.com/images/ss1ksk.png[^] In here I have 2 textboxes and a combobox whic has 2 items (administrator and instructor). I want to code under the add button. Namely, I want to save user name password and its role in a table. Here I have created a table.

http://www.imagetoo.com/images/ss2mdm.png[^]

I am noob guys, please help me. If you teach me how to insert I will develop delete update etc.

//UPDATE// here is my button code

Java
try {
      Connection con=null;
      Class.forName("oracle.jdbc.driver.OracleDriver");
      con=DriverManager.getConnection(
        "jdbc:oracle:thin:@AND ALSO HERE:1521:O10G",
        "plsql_staj",
        "plsql_staj1");
      Statement s=con.createStatement();
      s.execute("INSERT INTO E_USER VALUES(""I HAVE PROBLEM HERE")");
      s.close();
      con.close();
   } 
 catch(ClassNotFoundException | SQLException e){}





Thanks.
Posted
Updated 31-Jul-12 21:15pm
v2

1 solution

First setup a connection to your database.
Before trying to actually access the database from your program, try to connect to it using sqlplus from your development machine. This way you know that the connection string and tnsnames.ora is correct.
There is tons of information about this on the web.

http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html[^]

Then when it comes to inserting here is another link :

http://www.devdaily.com/java/edu/pj/jdbc/jdbc0002[^]

Also here there is a ton of information on the web.
 
Share this answer
 
Comments
FoxRoot 1-Aug-12 3:13am    
Thanks Philip as I mentioned I have searched a lot but something is wrong. Here is my button code. (Updated into question)
Philip Stuyck 1-Aug-12 3:30am    
Your insert statement should be something like this :
insert into e_user values('bla','bla','bla')
Like the second example I posted you have to assemble the string dynamically. There are other ways using parameters but this is a little more advanced.
I really think that with this last link I provided it should help you get this working.
FoxRoot 1-Aug-12 3:40am    
Yes I see but how could I send textboxes? insert into e_user values('bla','bla','bla') this is easy I want to solve this
s.execute("INSERT INTO E_USER VALUES(((u_name,u_pass,u_role)('"+txtAddUserName.getText()+"','"+txtAddUserPassWord.getText()+"','"+cmbAddUserRole.getSelectedItem().toString()+"')");
Philip Stuyck 1-Aug-12 4:03am    
your insert statement looks wrong to me since you are specifying the column names in the values.
Look at this :
http://psoug.org/definition/INSERT.htm
bottom line is
INSERT INTO users
(first_name, last_name)
VALUES
('john', 'smith');
Philip Stuyck 1-Aug-12 4:08am    
As a general tip. Try out your insert statement manually first. If you can insert it manually in the database, that sql statement is the one you need to create by code. You can also use a temp string variable and print it or debug it to see what is actually the string you are using for your insert.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900