简体   繁体   中英

Java connectivity to database

I am beginner in Java. I am making a program in which i am trying to connect java to mysql database but when i add these:

String Name=t1.getText();
String Mobile=t2.getText();
String Email=t3.getText();

 try
     {
         Class.forName("com.mysql.jdbc.Driver");
         Connection con=(Connection)
 DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","sagar");
         Statement stmt=(Statement)con.createStatement();

       String insert="INSERT INTO contact VALUES('"+Name+"','"+Moblie+"''"+Email+"');";
       stmt.executeUpdate(insert);



     }
     catch(Exception e)
     {
         JOptionPane.showMessageDialog(null, e.getMessage() ,"Error", 1);

     }

I got lots and lots of error above and below the code, even in the declared values.

Please suggest something, in my school book nothing is given about that.

Your data source URL is incorrect, try changing it to below. host name and port should be separated by : ,

"jdbc:mysql://localhost:3306/test"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM