wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes insert into spesific database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "insert into spesific database" Watch "insert into spesific database" New topic

insert into spesific database

sajeevi bangamuwage

Joined: Jan 19, 2005
Posts: 21
Hi all,

i have successfully connect to my SQL server.I have create tables,Insert values and also select all values & display.my server is working properly.
but i cant find where those tables r in my server.also i have created a Database in my server & i want to add those tables into that DB.How can i write codings to do that.here now i write my program.


Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://;user=stromme;password=stromme");
Statement stmt=conn.createStatement( );

String qry="create table studentMS(stdno varchar(32),marks1 integer,marks2 integer);";
String qryi1="insert into studentMS(stdno,marks1,marks2) Values('Madhuranga',86,97);";
int no1=stmt.executeUpdate(qry);
int no2=stmt.executeUpdate(qryi1);

String qry2="select * from studentMS;";
ResultSet rs=stmt.executeQuery(qry2);

String s=rs.getString("stdno");
int i1=rs.getInt("marks1");
int i2=rs.getInt("marks2");
System.out.println(s+" "+i1+" "+i2);
catch(Exception ex){
System.err.println("SQLException: " + ex.getMessage());

Thank you.
Sajeevi Bangamuwage.(SCJP)
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Configure your driver to connect to specific database or use "USE DBNAME"

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
sajeevi bangamuwage

Joined: Jan 19, 2005
Posts: 21

Thank you very much. i get the answer.

I agree. Here's the link: http://aspose.com/file-tools
subject: insert into spesific database
It's not a secret anymore!